home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / pas_all.zip / TI161.ASC < prev    next >
Text File  |  1991-09-11  |  8KB  |  265 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.   PRODUCT : TURBO PASCAL                               NUMBER : 161
  10.   VERSION : 2.0xx, 3.0xx
  11.        OS : MSDOS
  12.      DATE : March 13, 1986                               PAGE : 1/4
  13.     TITLE : MEMORY MAP INFORMATION
  14.  
  15.  
  16.  
  17.  
  18.   1.   When TURBO.COM is executed, MS-DOS builds a program segment
  19.        prefix in the lower 100H bytes of memory, and loads the
  20.        code immediately above. MS-DOS then jumps to CS: 100H.  When
  21.        Turbo Pascal gains control, it sets the DS register to point
  22.        at the first free paragraph after the code, and SS:SP to
  23.        point at top of memory. The latter is achieved by loading
  24.        Memtop-1000H into SS and 0FFFFH into SP.  Memtop is the
  25.        paragraph address of top of memory, and  it is passed by
  26.        MS-DOS at CS:02H in the program segment prefix.
  27.  
  28.        In systems with little RAM, Memtop-DS may be less than 1000H
  29.        (64K bytes), and in that case SS is set to the same
  30.        paragraph address as DS and SP is set to (Memtop-DS)?16.  In
  31.        the maps that follow we assume that Memtop-DS is greater
  32.        than 1000H.
  33.  
  34.        When using the Editor, memory is mapped as follows:
  35.  
  36.      CS:0000 - CS:00FF   MS-DOS PROGRAM SEGMENT PREFIX
  37.      CS:0100 - CS:E0RC   RUN-TIME LIBRARY CODE
  38.      CS:E0RC - CS:E0CC   MONITOR, EDITOR AND COMPILER CODE
  39.      DS:0000 - DS:E0RW   RUN-TIME LIBRARY DATA
  40.      DS:E0RW - DS:E0CW   MONITOR, EDITOR AND COMPILER DATA
  41.      DS:E0CW - DS:EOEM   ERROR MESSAGES (IF LOADED)
  42.      DS:E0EM - DS:????   SOURCE TEXT
  43.      SS:???? - SS:FFFF   CPU STACK
  44.  
  45.  
  46.        When the compiler is invoked to compile a program in memory,
  47.        it creates a new code segment immediately above the source
  48.        text. The PSP (Program Segment Prefix) and the run-time
  49.        library are copied from Turbo Pascal's code segment. The
  50.        reason Turbo Pascal creates a second copy of the run-time
  51.        library is that it does not support intersegment references.
  52.        All calls to run-time routines  must originate from
  53.        locations in the same code segment.  During an in-memory
  54.        compilation, memory is mapped as follows:
  55.  
  56.      CS:0000 - CS:00FF   MS-DOS PROGRAM SEGMENT PREFIX
  57.      CS:0100 - CS:E0RC   RUN-TIME LIBRARY CODE
  58.      CS:E0RC - CS:E0CC   MONITOR, EDITOR AND COMPILER CODE
  59.      DS:0000 - DS:E0RW   RUN-TIME LIBRARY DATA
  60.      DS:E0RW - DS:EOCW   MONITOR, EDITOR AND COMPILER DATA
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.   PRODUCT : TURBO PASCAL                               NUMBER : 161
  76.   VERSION : 2.0xx, 3.0xx
  77.        OS : MSDOS
  78.      DATE : March 13, 1986                               PAGE : 2/4
  79.     TITLE : MEMORY MAP INFORMATION
  80.  
  81.  
  82.  
  83.  
  84.      DS:E0CW - DS:E0EM   ERROR MESSAGES (IF LOADED)
  85.      DS:O0EM - DS:EOST   SOURCE TEXT
  86.  
  87.      CP:0000 - CP:00FF   MS-DOS PROGRAM SEGMENT PREFIX (COPY)
  88.      CP:0100 - CP:E0RC   RUN-TIME LIBRARY CODE (COPY)
  89.      CP:E0RC - CP:????   PROGRAM CODE
  90.      SS:???? - SS:FC00   SYMBOL TABLE
  91.      SS:???? - SS:FFFF   CPU STACK
  92.  
  93.        To execute the finished program, Turbo Pascal simply does a
  94.        far jump to offset 100H in the new program segment  (CP). It
  95.        will then look to the program as if it had been executed
  96.        from MS-DOS.
  97.  
  98.        When a Turbo Pascal program is executed in memory or from
  99.        MS-DOS, it maps memory as shown below:
  100.  
  101.      CS:0000 - CS:00FF   MS-DOS PROGRAM SEGMENT PREFIX (COPY)
  102.      CS:0100 - CS:E0RC   RUN-TIME LIBRARY CODE (COPY)
  103.      CS:E0RC - CS:E0PC   PROGRAM CODE
  104.      DS:0000 - DS:E0RW   RUN-TIME LIBRARY DATA
  105.      DS:E0RW - DS:E0PW   PROGRAM DATA
  106.      HS:0000 - ???????   HEAP (TOP ADDRESS IN HEAPPTR)
  107.      SS:???? - SS:FFFF   CPU STACK
  108.  
  109.        On entry, DS is set to point just above the code segment,
  110.        and the heap pointer (HeapPtr) is set to point just above
  111.        the data segment. SS:SP is set to point at top of memory,
  112.        using the same technique as when Turbo Pascal itself is
  113.        executed.
  114.  
  115.        When a program terminates, it either returns to MS-DOS
  116.        (using system function 0) or it does a far jump back to
  117.        Turbo Pascal, depending on a flag in the program code.
  118.  
  119.        Typed constants are stored in the code segment and, except
  120.        for their base segment (CS versus DS), correspond to
  121.        variables in all aspects. Untyped constants are never stored
  122.        in the sense that they have a fixed address somewhere in
  123.        memory. An untyped constant is only coded when used in an
  124.        expression and is usually moved into a register or onto the
  125.        stack, in this case.
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.   PRODUCT : TURBO PASCAL                               NUMBER : 161
  142.   VERSION : 2.0xx, 3.0xx
  143.        OS : MSDOS
  144.      DATE : March 13, 1986                               PAGE : 3/4
  145.     TITLE : MEMORY MAP INFORMATION
  146.  
  147.  
  148.  
  149.  
  150.   2.   There is no recursion stack in the 16-bit versions of Turbo
  151.        Pascal. It is only in the 8-bit version that the CPU stack
  152.        and the recursion stack are separated. The 16-bit version
  153.        implements a true "stack frame" concept, meaning that all
  154.        local variables are allocated on the CPU stack and addressed
  155.        through the BP (Base Page) CPU register.
  156.  
  157.   3.   The CSEG, DSEG, and SSEG return the contents of the CS, DS,
  158.        and SS Registers, respectively. However, contrary to the
  159.        other segment registers, the value of the ES register is not
  160.        fixed. Turbo Pascal will initialize it when it uses it. ES
  161.        is used heavily by the run-time library routines and plays
  162.        an active role in most 8086 string instructions (MOVS, STOS,
  163.        CMPS, etc.). It is also used to access variables indirectly,
  164.        such as variable parameters and pointers. You can use ES any
  165.        way you like in your routines, but do not make any
  166.        assumptions about its initial value.
  167.  
  168.   4.   The fields of the PSP are easily accessed by declaring them
  169.        as absolute variables in the code segment. For instance:
  170.  
  171.        var CMDLine: String(127) absolute CSeg:$80H
  172.  
  173.        which declares a variable to access the command line passed
  174.        by MS-DOS in the PSP.
  175.  
  176.        The chain and execute procedures store 0FF in the byte at
  177.        CS:80H to indicate that the program was invoked from another
  178.        program and not from MS-DOS. Otherwise, the PSP is not
  179.        changed during a chain/execute operation. Turbo Pascal only
  180.        accesses the PSP to find the address of top of memory and to
  181.        write the chain/execute flag as described above.
  182.  
  183.   5.   There is no official way to catch run-time errors in the
  184.        current versions of Turbo Pascal.
  185.  
  186.   6.   When a COM File is invoked from MS-DOS, all segment
  187.        registers are set to point at the program segment prefix.
  188.        This initial value is retained in the CS register during
  189.        execution, and you can obtain it through the CSEG function.
  190.  
  191.   7.   Turbo Pascal initializes the divide-by-zero interrupt vector
  192.        (Interrupt 0). When the U compiler option is activated with
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.   PRODUCT : TURBO PASCAL                               NUMBER : 161
  208.   VERSION : 2.0xx, 3.0xx
  209.        OS : MSDOS
  210.      DATE : March 13, 1986                               PAGE : 4/4
  211.     TITLE : MEMORY MAP INFORMATION
  212.  
  213.  
  214.  
  215.  
  216.        an {$U+} directive, Turbo Pascal initializes interrupt
  217.        vector 3 to point at a Ctrl-C check routine. In both cases,
  218.        MS-DOS system function 25 (set vector) is used to carry out
  219.        the initialization.
  220.  
  221.   8.   There is no additional information available on the inner
  222.        workings of the Turbo Pascal initialization routines (front
  223.        end). However, most if not all of the tasks carried out by
  224.        it are covered in the reference manual and the above
  225.        answers.
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.